<template>
	<view class="content">
		<uni-nav-bar left-icon="home" statusBar @clickLeft="back" title="订单状态" backgroundColor="rgba(0,0,0,0)">
			<block slot="right">
				<text style="
				font-size: 26rpx;
				color: #08090A;"
				v-if="type == 1" 
				@click="toContent">查看详情</text>
			</block>
		</uni-nav-bar>
		<view class="pay-status">
			<image src="https://qiniu-cdn.maeiyun.com/imgs/pay/payimg.png" mode=""></image>
			<view>{{status}}</view>
		</view>
		<view class="order-info">
			<view class="price">
				<text>￥</text>
				{{payData.price || ''}}
			</view>
			<view class="order-data">
				<view>订单编号: {{payData.order_sn || ''}}</view>
				<view>下单时间: {{payData.createtime || ''}}</view>
				<view>支付方式:{{payData.pay_type == 1?'微信支付':payData.pay_type == 2?'支付宝支付':payData.pay_type == 3?'苹果支付':'其他支付'}}</view>
			</view>
		</view>
		
		<view class="btn" @click="back">确认</view>
		
		
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				order_id:"",
				payData:{},
				
				type:0,
				
				num:0,
				
				status:'支付状态查询中',
				pay_type:1,
			}
		},
		onLoad(option) {
			this.order_id = option.order_id?option.order_id:''
			if(option.type){
				this.type = option.type
				this.pay_type = option.pay_type
			}
			this.getPayStatus()
		},
		onBackPress() {
			uni.switchTab({
				url:'/pages/index/index'
			})
			return true
		},
		methods: {
			back(){
				uni.switchTab({
					url:"/pages/order/order"
				})
			},
			toContent(){
				uni.navigateTo({
					url:'/otherpages/order/content/film?order_id=' + this.order_id
				})
			},
			getPayStatus() {
				uni.showLoading({
					mask: true
				})
				let that = this
				let order = {
					order_id: this.order_id,
					pay_type: this.pay_type
				};
				that.request.httpTokenRequest({
					url: "pay/get_pay_status",
					method: "post",
				}, order).then(function(data) {
					if (data.code == 0) {
						that.payData = data.data.order_info
						uni.hideLoading()
						that.status = '支付成功'
					} else {
						that.num++
						if (that.num < 4) {
							setTimeout(() => {
								that.getPayStatus()
							}, that.num * 1000)
						} else {
							uni.hideLoading()
							that.status = '订单查询失败'
							that.$refs.uToast.show({
								title: '订单查询失败',
								type: 'warning',
								back: true,
							})
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.content {
		// padding-top: calc(var(--status-bar-height)+44px);
	}
	.btn {
		width: 300rpx;
		height: 88rpx;
		background: #EF5233;
		border-radius: 44rpx;
		font-size: 34rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		margin: 30rpx auto 0;
	}
	.pay-status{
		font-size: 40rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #EF5233;
		text-align: center;
		margin-bottom: 52rpx;
		image{
			width: 240rpx;
			height: 240rpx;
			margin-bottom: 25rpx;
		}
	}
	.nav {
		// position: fixed;
		// top: 0;
		// left: 0;
		// width: 100%;
		// background: #FFF;
		// z-index: 99;
		// padding-top: var(--status-bar-height);
	}
	.order-info{
		background: url('https://qiniu-cdn.maeiyun.com/imgs/pay/bg.png')no-repeat;
		background-size: 100% 100%;
		width: 690rpx;
		height: 344rpx;
		margin: 0 auto;
		padding-top: 52rpx;
		box-sizing: border-box;
		.price{
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 50rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			color: #EF5233;
			text{
				font-size: 22rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #EC2700;
			}
		}
		.order-data{
			margin: 30rpx auto;
			width: 80%;
			border-top: 1rpx dashed #B9B9B9;
			font-size: 22rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: #8A8A8A;
			line-height: 44rpx;
			padding-top: 28rpx;
		}
	}
</style>